-- 冈布奥触发事件

-- 内部函数
local registerEffectEvent;

function initSlimeEvent(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);
    local dbase =  DungeonM.queryElement(self.gridData.element, "dbase");
    local pos = self.gridData:getPos();

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    -- 注册事件函数
    registerEffectEvent();

    if class == 600 then
        -- 男巫小屋
        require "game/ui/form/dungeon/grid/slime_event/gargamelSlime";
        initGargamelSlime(self, buildingInfo, dbase, pos);
    elseif class == 601 then
        -- 佐罗冈布奥
        require "game/ui/form/dungeon/grid/slime_event/zooroSlime";
        initZooroSlime(self, buildingInfo, dbase, pos);
    elseif class == 602 then
        -- 铁血战士冈布奥
        require "game/ui/form/dungeon/grid/slime_event/predatorSlime";
        initPredatorSlime(self, buildingInfo, dbase, pos);
    elseif class == 603 then
        -- 王子冈布奥
        require "game/ui/form/dungeon/grid/slime_event/princeSlime";
        initPrinceSlime(self, buildingInfo, dbase, pos);
    elseif class == 604 then
        -- 巫妖雕像
        require "game/ui/form/dungeon/grid/slime_event/witchStatue";
        initWitchStatue(self, buildingInfo, dbase, pos);
    elseif class == 605 then
        -- 血猎者冈布奥
        require "game/ui/form/dungeon/grid/slime_event/bloodHunterSlime";
        initBloodHunterSlime(self, buildingInfo, dbase, pos);
    elseif class == 606 then
        -- 船长小屋
        require "game/ui/form/dungeon/grid/slime_event/captainCabin";
        initCaptainCabin(self, buildingInfo, dbase, pos);
    elseif class == 607 then
        -- 猛犸
        require "game/ui/form/dungeon/grid/slime_event/mammoth";
        initMammoth(self, buildingInfo, dbase, pos);
    elseif class == 608 then
        -- 仙女
        require "game/ui/form/dungeon/grid/slime_event/fairySlime";
        initFairySlime(self, buildingInfo, dbase, pos);
    elseif class == 609 then
        -- 匹诺曹
        require "game/ui/form/dungeon/grid/slime_event/pinocchioSlime";
        initPinocchio(self, buildingInfo, dbase, pos);
    elseif class == 3014 then
        -- 未来猫
        require "game/ui/form/dungeon/grid/slime_event/doraemon";
        initDoraemon(self, buildingInfo, dbase, pos);
    else
        error("错误的类型配置，元素类型：" .. class);
        return;
    end
end

-- 关注奖励效果事件
function registerEffectEvent()
    EventMgr.removeAll("UIGrid/SlimeEvent");
    EventMgr.register("UIGrid/SlimeEvent", event.SLIME_EVENT_EFFECT, function(params)
        local eventId   = params.eventId;
        local bonusTip  = params.bonusTip;
        local callback  = params.callback;
        local bonusList = params.bonusList;
        local pos       = params.pos;

        local dbase = SlimeEventM.query(eventId, "dbase");
        if dbase["no_talk"] and dbase["dungeon_bonus"] then
            -- 弹字
            alert(bonusTip);
            -- 奖励
            callback();

            -- 抛出一个捡物品事件（做效果）
            EventMgr.fire(event.PICK_UP_ITEM, {
                ["bonus"]         = bonusList,
                ["pos"]           = pos or 13,
                ["newBonus"]      = true,
                ["type"]          = GRID_TYPE_ITEM,
                ["noAlert"]       = true,
                ["isItemVisible"] = true,
                ["borrowGrid"]    = true,
            });
        end
    end);
end
